package core

import (
	"fmt"
	"github.com/go-playground/validator/v10"
)

type Validate struct{}

func (m *Validate) ErrorMsg(me interface{}, d map[string]interface{}) string {
	var msg string
	switch e := me.(type) {
	case validator.ValidationErrors:
		for _, v := range e {
			for k2, v2 := range d {
				if v.StructField() == k2 {
					switch i := v2.(type) {
					case string:
						msg = v2.(string)
						goto breakHere
					case map[string]string:
						for m, j := range i {
							if v.ActualTag() == m {
								msg = j
								goto breakHere
							}
						}
					}
				}
			}
		}

		msg = e.Error()
	case *validator.InvalidValidationError:
		fmt.Println(e.Error())
	}
breakHere:
	return msg
}
